<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title>追加排班</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../common/mui/mui.css" rel="stylesheet" />
		<link href="../../common/css/app.css" rel="stylesheet" />
		<link href="../../dependence/teach/css/teachPublic.css" rel="stylesheet" />
		<style type="text/css">
			#wrapper{
				top: calc(var(--searchHeight) + var(--size50) + 44px);
				bottom: var(--size50);
			}
			.searchArea{
				background-color: white;
			}
			table{
				table-layout: fixed;
				width: 100%;
				border-collapse: separate;
				border-spacing: 0;
				border-radius: 0;
				background-color: white;
				font-size: var(--size14);
				color: var(--textColor);
			}
			.tableHead{
				margin-top: var(--size10);
			}
			.circle{
				display: inline-block;
				width: var(--size16);
				height: var(--size16);
				font-size: var(--size16);
				line-height: 1;
				color: #CECECE;
			}
			.circle::after{
				font-family: Muiicons;
				-webkit-font-smoothing: antialiased;
				content: '\e411';
			}
			td{
				height: var(--size40);
				border-bottom: solid 1px #EFEFEF;
				padding-left: var(--size8);
			}
			td:first-child{
				border-bottom-color: transparent;
				text-align: center;
			}
			tr.mui-active .circle::after{
				content: '\e441';
				color: var(--mainColor);
			}
			tr:last-child td{
				border: none;
			}
			.appendTips{
				font-size: var(--size12);
				color: gray;
				padding: var(--size10) var(--size15);
			}
			.bottomArea{
				height: var(--size50);
				position: absolute;
				top: auto;
				bottom: 0;
				left: 0;
				width: 100%;
			}
			#cancelBtn,#appendBtn{
				height: 100%;
				width: 50%;
				background-color: var(--mainColor);
				margin: 0;
				padding: 0;
				font-size: var(--size14);
				line-height: var(--size50);
				float: left;
				border: none;
				border-radius: 0;
			}
			#cancelBtn{
				background-color: white;
				color: var(--mainColor);
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">追加排班</h1>
		</header>
		<div class="mui-content">
			<div class="searchArea">
				<div class="mui-input-row mui-search">
					<input id="search" type="search" class="mui-input-clear" placeholder="搜索课程"/>
				</div>
			</div>
			<table class="tableHead">
				<colgroup><col width="15%"><col width="35%"><col width="50%"></colgroup>
				<thead><tr><td></td><td>班次名称</td><td>时间段</td></tr></thead>
			</table>
			<div id="wrapper" class="mui-scroll-wrapper">
				<div id="scroll" class="mui-scroll mui-scroll-phone">
					<table><colgroup><col width="15%"><col width="35%"><col width="50%"></colgroup>
						<tbody id="tbody"></tbody>
					</table>
					<div class="appendTips">*以上为已选排班无交叉时间的班次，支持班次多选</div>
				</div>
			</div>
			<div class="bottomArea">
				<div id="cancelBtn" class="mui-btn mui-btn-primary">取消</div>
				<div id="appendBtn" class="mui-btn mui-btn-primary">增加</div>
			</div>
		</div>
		
		<script src="../../common/mui/mui.js"></script>
		<script src="../../common/js/jquery-3.4.1.min.js"></script>
		<script src="../../common/js/globalSet.js"></script>
		<script src="../../common/js/DHCWebService.js"></script>
		<script type="text/javascript">
			var nurseid='',sourceData,allArr;
			mui.init()
			mui.plusReady(function () {
			    baseSetup();
			})
			if (!mui.os.plus) {
				baseSetup()
			}
			function getPostData(){
				var pdict = {"start":0,'limit':"",'parr':'^'+sourceData['wardId']+'^'}
				var paramDict = {'method':'web.INMDBComm:FindWardPostList','params':JSON.stringify(pdict),'type':'RecQuery'}
				//console.log(JSON.stringify(pdict));
				mui.DHCWebService(paramDict, function(result) {
					//console.log(JSON.stringify(result))
					if (result['msgcode'] != '1') {
						mui.toast(result['msg'])
						mui('#tbody')[0].innerHTML = ''
						return
					}
					var dataArr = result['data']
					allArr = dataArr
					var html = ''
					for (var i = 0; i < dataArr.length; i++) {
						var oneData = dataArr[i]
						var timeStr = oneData['PostStTime1']+'-'+oneData['PostEndTime1']
						if (oneData['PostStTime2'] != '') {
							timeStr += ' '+oneData['PostStTime2']+'-'+oneData['PostEndTime2']
						}
						if (oneData['PostStTime3'] != '') {
							timeStr += ' ' + oneData['PostStTime3']+'-'+oneData['PostEndTime3']
						}
						html +='<tr data-index="'+i+'" data-sch="'+oneData['PostDesc']+'"><td><div class="circle"></div></td><td>'+oneData['PostDesc']+'</td><td>'+timeStr+'</td></tr>'
					}
					mui('#tbody')[0].innerHTML = html
					mui.each(sourceData['sch'].split('%'),function (cateIndex,oneCate) {
						if (cateIndex == 2 || oneCate == "") {//0为班次,1位请假(个人走的请假流程),2为未审批的个人意愿班次
							return
						}
						var arr = oneCate.split('「') //多个班次分隔
						mui.each(arr,function (schIndex,oneSch) {
							if (oneSch == "") return
							var tmpArr = oneSch.split('」')
							var mainStr = tmpArr[1]
							var mainArr = mainStr.split('『')
							mui('#tbody tr[data-sch="'+mainArr[0]+'"]').each(function (index,element) {
								element.style.display = 'none'
							})
						})
					})
				}, function(errorStr) {
					// mui.toast('请重试')
				});
			}
			
			function dealUndefined(str){
				if (str == undefined || str == null) {
					return ''
				}
				return str
			}
			
			function appendBtnTapped(argInfo,locSchArr,perIndex){
				var schs =''
				mui('#tbody .mui-active').each(function (index,element) {
					var trIndex = element.getAttribute('data-index');
					var dict = allArr[trIndex]
					if (index > 0) {
						schs += ','
					}
					schs += dict['rw']
				})
				var perInfo = locSchArr[perIndex]
				//parr:排班表Id^行Id^护士person Id^排班日期^病区班次Id
				var pdict = {'parr':argInfo['rw']+'^'+perInfo['ArgRowId']+'^'+perInfo['ArgPerDR']+'^'+sourceData['date']+'^'+schs,'nurseid':nurseid};
				//console.log(JSON.stringify(pdict))
				var paramDict = {'method':'web.INMArgComm:SaveArgSubMultiple','params':JSON.stringify(pdict),'type':'Method'}
				mui.DHCWebService(paramDict, function(result) {
					//console.log(JSON.stringify(result))
					if (result['msg'] == '1') {//保存成功
						var schLocPage = plus.webview.getWebviewById('nurSchLoc')
						if (schLocPage) {
							schLocPage.evalJS('refreshPageData("sch")')
						}
						mui.back()
					}else{
						mui.toast(result['msg'])
					}
				}, function(errorStr) {
					mui.toast('请重试')
				});
			}
			
			function selectSchInfo(){
				var classStr = this.getAttribute('class');
				if (!classStr || classStr.indexOf('mui-active') == -1) {
					this.classList.add('mui-active')
				}else{
					this.classList.remove('mui-active')
				}
			}
			
			function baseSetup(){
				mui('.mui-scroll-wrapper').scroll({
					bounce: true,
					indicators: false, //是否显示滚动条
				});
				mui('#tbody').on('tap','tr',selectSchInfo);
				mui('#cancelBtn')[0].addEventListener('tap',mui.back)
				mui('#appendBtn')[0].addEventListener('tap',function(){
					if (sourceData['rw'] != "") {
						appendBtnTapped(sourceData['argInfo'],sourceData['locSchArr'],sourceData['index'])
						return
					}
					var schLocPage = plus.webview.getWebviewById('nurSchLoc')
					if (schLocPage) {
						schLocPage.evalJS('refreshPageData("create","nurSchAdd","appendBtnTapped")')
					}
				})
				
				var self = plus.webview.currentWebview();
				sourceData = self.sourceData;//{'wardId':wardID,'sch':schStr,'date':dateStr,'ArgPerDR':ArgPerDR,'ArgRowId':ArgRowId,rw:argInfo['rw']}
				nurseid=sourceData['nurseid']
				getPostData();
			}
		</script>
	</body>

</html>
